# -*- encoding=utf8 -*-

__author__ = "code哥"
import json
from sanic.blueprints import Blueprint
from sanic.views import HTTPMethodView
from sanic import response
from sanic_openapi import doc
from conn_pool import get_redis, REDIS_APP_EXECUTION_TIME_KEY

rs = get_redis()

blueprint = Blueprint(__name__, '/api')


class APPExecutionTime(HTTPMethodView):

    @doc.summary("获取APP执行时间")
    def post(self, request):
        redis_exec_list = rs.get(REDIS_APP_EXECUTION_TIME_KEY)
        exec_list = []
        if redis_exec_list is not None and len(str(redis_exec_list)) > 0:
            exec_list = json.loads(redis_exec_list, encoding='utf-8')
        return response.json({'code': 0, 'data': exec_list})


blueprint.add_route(APPExecutionTime.as_view(), '/app_exec_time_list', strict_slashes=True)
